#include "GameText.h"
#include <iostream>
using namespace std;

GameText::GameText(GameState *gameState) : GameObject(gameState){
	addProperty("GameText");
	setLayer(0);
	setColor(0.275, 0.216, 0.098);
	m_alignment = LEFT;
	m_fontSize = 30;

}

void GameText::update(double dt){
	
}


void GameText::draw(){
	m_gameState->getWindow()->pushGLStates();

	Text text(m_text, m_gameState->getFont(), m_fontSize);

	b2Vec2 pos(getPosition());
	pos -= b2Vec2(m_gameState->camera.posX, m_gameState->camera.posY);
	b2Vec2 uPerPix(800.0f/m_gameState->camera.widthUnits,
		600.0f/m_gameState->camera.heightUnits);

	pos.x += m_gameState->camera.widthUnits/2.0f;
	pos.y -= m_gameState->camera.heightUnits/2.0f;

	pos.x *= uPerPix.x;
	pos.y *= -uPerPix.y;

	FloatRect bounds = text.getLocalBounds();
	
	switch(m_alignment){
	case CENTER:
		pos.x -= bounds.width*0.5;
		break;
	case RIGHT:
		pos.x -= bounds.width;
		break;
	}

	text.setPosition(pos.x, pos.y);
	

	text.setColor(Color(m_color[0]*255, m_color[1]*255, m_color[2]*255, m_color[3]*255));
	m_gameState->getWindow()->draw(text);
	m_gameState->getWindow()->popGLStates();
}


